package cn.ttxs.wq;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;

import com.google.android.material.tabs.TabLayout;
import com.vondear.rxtool.view.RxToast;

import java.util.ArrayList;
import java.util.List;

import cn.ttxs.lib.base.BaseFragment;
import cn.ttxs.lib.base.PageFragment;
import cn.ttxs.lib.tool.ToolLog;
import cn.ttxs.lib.wiget.NoscrollViewPager;
import cn.ttxs.wq.adapter.FragmentAdapter;
import cn.ttxs.wq.fragment.HomeFragment;
import cn.ttxs.wq.fragment.MsgFragment;
import cn.ttxs.wq.fragment.WorkFragment;

public class MainActivity extends AppCompatActivity {

    private TabLayout tab_layout;
    private NoscrollViewPager view_pager;
    private List<BaseFragment> fragmentList = new ArrayList<>();
    private BaseFragment homeFragment, msgFragment, workFragment, mineFragment;
    private String[] titleArr = new String[]{"首页", "消息", "工作", "我的"};
    private PagerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        setView();
    }


    private void initView() {
        ToolLog.w("http", "-----------");
        tab_layout = findViewById(R.id.tab_layout);
        view_pager = findViewById(R.id.view_pager);
    }



    private void initData() {
        homeFragment = HomeFragment.newInstance(0);
        msgFragment = MsgFragment.newInstance(1);
        workFragment = WorkFragment.newInstance(2);
        mineFragment = PageFragment.newInstance(3);
        fragmentList.add(homeFragment);
        fragmentList.add(msgFragment);
        fragmentList.add(workFragment);
        fragmentList.add(mineFragment);

    }

    private void setView() {
        adapter = new FragmentAdapter(getSupportFragmentManager(), fragmentList, titleArr);
        view_pager.setAdapter(adapter);
        tab_layout.setupWithViewPager(view_pager);

    }

}